package createThread;

import threadLocalTest.Profiler;

import java.util.concurrent.TimeUnit;
import java.util.concurrent.locks.Lock;
import java.util.concurrent.locks.ReentrantLock;

/**
 * @program: javase
 * @description: 使用标志位 结束线程
 * @author: lld
 * @create: 2021-03-21 17:03
 **/
public class Thread4 implements Runnable {
    private boolean flag = true;

    public static void main(String[] args) throws InterruptedException {
        Thread4 thread4 = new Thread4();
        Thread thread = new Thread(thread4);
        thread.start();
        Thread thread1 = new Thread(thread4);
        thread1.start();
        TimeUnit.SECONDS.sleep(1);
        thread4.stop();

    }

    public void stop() {
        flag = false;
        System.out.println("结束");
    }

    @Override
    public void run() {
        while (flag) {
            System.out.println("正在执行");
        }
    }
}
